var groupAnagrams = function(strs) {
  const map = new Map();
  const ans = [];

  for (let i = 0; i < strs.length; i++) {
    const temp = strs[i].split("").sort().join("");
    if (map.has(temp)) {
      map.set(temp, [...map.get(temp), strs[i]]);
    } else {
      map.set(temp, [strs[i]]);
    }
  }

  for (const item of map) {
    ans.push(item[1]);
  }

  return ans;

};

const strs = ["eat", "tea", "tan", "ate", "nat", "bat"];
console.log(groupAnagrams(strs))